package com.tlias.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

@Slf4j
@Component//拦截器需要加@Component注解是Spring管理的类
//拦截器(Interceptor),需要实现拦截器接口(HandlerInterceptor)  需要配合拦截器配置类(WebMvcConfigurer)->>>Webconfig
public class DemoInterceptor implements HandlerInterceptor {
    //日标方法执行前触发--返回true代表放行:返回false，代表不放行  非常常用
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("preHandle...方法执行前触发");
        return true;//返回true代表放行:返回false
    }
    //日标方法执行后触发
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        log.info("postHandle...方法执行后触发");
    }
    //日标方法执行完成后触发最后出发的方法
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("afterCompletion...方法执行完成后触发最后出发的方法");
    }

}
